import axios from "./request";
import { IErrorData, ISuccessPageData } from "./returnData";

// 数据对象
export interface IMessageObj {
    nickname: string,
    content: string,
    createDate: number,
    avatar: string,
    id: string
}

// 条件约束
export interface IMessageQuery {
    page: number,
    limit: number,
    keyword: string
}

// 留言数据约束
export interface IMessageRes {
    total: number,
    rows: IMessageObj[]
}

/**
 * 分页获取数据
 * @param query 
 * @returns 
 */
export function getPageMessage(query: IMessageQuery = { page: 1, limit: 5, keyword: "" }): Promise<ISuccessPageData<IMessageRes> | IErrorData> {
    return axios.get(`/api/message`, {
        params: query
    });
}

/**
 * 删除留言
 * @param id 留言id值
 * @returns 
 */
export function deleteMessage(id: string): Promise<ISuccessPageData<boolean> | IErrorData> {
    return axios.delete(`/api/message/${id}`)
}